﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string ch;
            do
            {
                Console.Clear();
                Console.WriteLine("Use keys 1-8 to choose the task.");
                Console.WriteLine("1 - Task #1");
                Console.WriteLine("2 - Task #2");
                Console.WriteLine("3 - Task #3");
                Console.WriteLine("4 - Task #4");
                Console.WriteLine("5 - Task #5");
                Console.WriteLine("6 - Task #6");
                Console.WriteLine("7 - Task #7");
                Console.WriteLine("8 - Task #8");
                int userChoice = Int32.Parse(Console.ReadLine());
                switch (userChoice)
                {
                    case 1:
                        FirstTask();
                        break;
                    case 2:
                        SecondTask();
                        break;
                    case 3:
                        ThirdTask();
                        break;
                    case 4:
                        FourthTask();
                        break;
                    case 5:
                        Console.Clear();
                        Console.Write("Enter frame length: ");
                        int frameLength = Int32.Parse(Console.ReadLine());
                        Console.WriteLine("Enter frame width: ");
                        int frameWidth = Int32.Parse(Console.ReadLine());
                        Console.Write("Enter character which composes a frame: ");
                        char frameChar = Char.Parse(Console.ReadLine());
                        FifthTask(frameLength, frameWidth, frameChar);
                        break;
                    case 6:
                        Console.Clear();
                        Console.Write("Enter array size: ");
                        int arraySize = Int32.Parse(Console.ReadLine());
                        SixthTask(arraySize);
                        break;
                    case 7:
                        SeventhTask();
                        break;
                    case 8:
                       EightthTask();
                        break;
                    default:
                        Console.WriteLine("Error! Use keys 1-8!");
                        break;


                }

                Console.WriteLine("Do you want to continue? Y/N");
                ch = Console.ReadLine().ToLower();
            } while (ch == "y");

        }


        static void FirstTask()

        {
            Console.Clear();
            Console.Write("Enter whole number: ");
            int userNumber = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Operation: {0} + 10 = {1}", userNumber, (userNumber + 10));
        }

        static void SecondTask()
        {
            Console.Clear();
            int sumOfSequence = 0;
            Console.Write("Enter positive whole number: ");
            int userNumber = Int32.Parse(Console.ReadLine());

            if (userNumber <= 0)
            {
                Console.Clear();
                Console.WriteLine("Error! Please enter positive whole number!");
                Console.Write("Enter positive whole number: ");
                userNumber = Int32.Parse(Console.ReadLine());
            }
            for (int i = 0; i < (userNumber + 1); i++)
            {
                sumOfSequence = sumOfSequence + i;
            }
            Console.WriteLine("Summary of number sequence from 1 to {0} is {1}", userNumber, sumOfSequence);


        }

        static void ThirdTask()
        {
            Console.Clear();
            Console.WriteLine("Enter the X/Y coordinates of two points");
            Console.Write("First point X: ");
            int firstX = Int32.Parse(Console.ReadLine());
            Console.Write("First point Y: ");
            int firstY = Int32.Parse(Console.ReadLine());
            Console.Write("\nSecond point X: ");
            int secondX = Int32.Parse(Console.ReadLine());
            Console.Write("Second point Y: ");
            int secondY = Int32.Parse(Console.ReadLine());
            Console.Clear();
            Console.WriteLine("Point A ({0};{1})", firstX, firstY);
            Console.WriteLine("Point B ({0};{1})", secondX, secondY);
            double distanceAB = Math.Sqrt(Math.Pow((firstX - secondX), 2) + Math.Pow((firstY - secondY), 2));
            Console.WriteLine("A-B distance is {0}", Math.Round(distanceAB, 2));

        }

        static void FourthTask()
        {
            Console.Clear();
            Console.WriteLine("Enter the X/Y coordinates of two points");
            Console.Write("First point X: ");
            int firstX = Int32.Parse(Console.ReadLine());
            Console.Write("First point Y: ");
            int firstY = Int32.Parse(Console.ReadLine());
            Console.Clear();
            Console.WriteLine("Point A ({0};{1})", firstX, firstY);
            if ((firstX > 0) && (firstY > 0))
                Console.WriteLine("Point A locates in I quarter.");
            if ((firstX < 0) && (firstY > 0))
                Console.WriteLine("Point A locates in II quarter.");
            if ((firstX < 0) && (firstY < 0))
                Console.WriteLine("Point A locates in III quarter.");
            if ((firstX > 0) && (firstY < 0))
                Console.WriteLine("Point A locates in IV quarter.");
            if ((firstX == 0) && (firstY == 0))
                Console.WriteLine("Point A locates in the origin of coordinate system.");
            if (firstX == 0)
                Console.WriteLine("Point A locates on X-axis.");
            if (firstY == 0)
                Console.WriteLine("Point F locates on Y-axis.");
        }

        static int[,] FifthTask(int frameLength, int frameWidth, char ch)
        {
            Console.Clear();
            int[,] array = new int[frameLength, frameWidth];

            for (int i = 0; i < frameWidth; i++)
            {

                for (int j = 0; j < frameLength; j++)
                {
                    if ((i == (frameWidth - 1)) || (i == 0))
                        Console.Write(ch);
                    else if ((j == 0) || (j == (frameLength - 1)))
                        Console.Write(ch);
                    else
                        Console.Write(" ");
                }
                Console.WriteLine();
            }
            return array;
        }

        public static int[] SixthTask(int arraySize)
        {
            Console.Clear();
            int[] newArray = new int[arraySize];
            Random rnd = new Random();
            for (int i = 0; i < arraySize; i++)
            {
                newArray[i] = rnd.Next(1, 101);
               
            }
            return newArray;

        }

        public static void SeventhTask()
        {
            Console.Clear();
            int evenCount = 0;
            int oddCount = 0;
            int [] newArray = SixthTask(5);
            for (int i = 0; i<5; i++)
            {
              if ((newArray[i]%2)==0)
                {
                    evenCount += 1;
                }
              else if ((newArray[i]%2)!=0)
                {
                    oddCount += 1;
                }
              Console.WriteLine("[{0}]: {1}", i, newArray[i]);
            }
            Console.WriteLine("Amount of even elements in array: {0}", evenCount);
            Console.WriteLine("Amount of odd elements in array: {0}", oddCount);

        }

        public static void EightthTask()
        {
            Console.Clear();
            int maxPosition=0;
            int minPosition=0;
            int maxCount=0;
            int minCount=0;
            int[] newArray = SixthTask(5);
            for (int i = 0; i < 5; i++)
            {
               
                if (newArray[i] == newArray.Max())
                {
                    maxPosition = i;
                    maxCount += 1;
                }
                if (newArray[i]==newArray.Min())
                {
                    minPosition = i;
                    minCount += 1;
                }
                Console.WriteLine("[{0}]: {1}", i, newArray[i]);
            }
            Console.WriteLine("Position of first maximum element in the array: [{0}]", maxPosition);
            Console.WriteLine("Position of firstminimum element in the array: [{0}]", minPosition);
            Console.WriteLine("Total amount of maximum elements of the array: {0}", maxCount);
            Console.WriteLine("Total amount of minimum elements of the array: {0}", minCount);
        }
    }
}

